<template>
  <div id="blog-content">
    <el-timeline>
      <el-timeline-item :timestamp="blog.createTime" placement="top" v-for="blog in blogs">
        <el-card>
          <h4>
            <router-link :to="{name: 'BlogDetail', params: {blogId: blog.id}}">
              {{ blog.title }}
            </router-link>
          </h4>
          <p>{{ blog.description }}</p>
        </el-card>
      </el-timeline-item>
    </el-timeline>
    <el-pagination id="blog-page"
                   background
                   layout="prev, pager, next"
                   :current-page="currentPage"
                   :page-size="pageSize"
                   :total="total"
                   @current-change=getBlogs>
    </el-pagination>
  </div>
</template>

<script>
import * as constConfig from "../constData/ConstData";

export default {
  name: "Blogs",
  data() {
    return {
      blogs: {},
      currentPage: 1,
      total: 0,
      pageSize: 7
    }
  },
  methods: {
    getBlogs(currentPage) {
      this.$axios.get(constConfig.prefixApi + "/blogs?currentPage=" + currentPage).then(res => {
        this.blogs = res.data.data.records
        this.currentPage = res.data.data.current
        this.total = res.data.data.total
        this.pageSize = res.data.data.size
      })
    }
  },
  created() {
    this.getBlogs(1)
  }
}
</script>

<style scoped>
#blog-content {
  margin: auto;
  width: 70%;
}

#blog-page {
  margin: 0 auto;
  text-align: center;
}
a{
  text-decoration: none;
}
</style>